angular.module('starter.controllers', [])

.controller('top',function ($scope,$ionicScrollDelegate,$http,$timeout) {
		$scope.backTop = function () {
			$ionicScrollDelegate.scrollTop(true);
		}
		
})

.controller("city",['$scope','city','$location','$ionicScrollDelegate','$timeout',function (s,c,l,d,t) {
	c.selectCity().then(function (res) {
		s.cities = res.data.datas.list
		console.log(s.cities)
	})
	s.cityarr = c.cities
	
	s.close = false
	//是否显示清楚图标
	s.inp = function () {
		if(s.cityName == '' ){
			s.close = false
		}else{
			s.close = true
		}
	}
	//清楚输入框的点击事件
	s.inpEmpty = function () {
		s.cityName = ''
		s.close = false;
	}
	//点击字母滚动
	s.showMiddle = false
	s.mTouch = function (c) {
		s.showMiddle = true;
		s.hint = c;
		l.hash('city_' + s.hint)
		d.anchorScroll(true)
		t(function () {
			s.showMiddle = false
		},500)
		s.cityName = ''
	}
}])

.controller('findMore', ["$scope","find",'$ionicScrollDelegate','$timeout',function(s,f,i,t) {
//	console.log(f.findMoreData())
	f.findMoreData()
	.then(function (res) {
		s.find = res.data.datas
//		console.log(s.find)
	})
	s.tic = true
	s.loadMore = function () {
		f.loadMore()
		.then(function (res) {
			s.find = s.find.concat(res.data.datas)
			s.$broadcast('scroll.infiniteScrollComplete');
			if (s.find.length == s.find.concat(res.data.datas).length) {
				s.tic = false
			}
		})
	}
	f.around().then(function (res) {
		s.findaround = res.data.datas
//		console.log(s.findaround)
	})
	s.arr = true
	s.aroundMore = function () {
		f.aroundMore()
		.then(function (res) {
			s.findaround = s.findaround.concat(res.data.datas)
			s.$broadcast('scroll.infiniteScrollComplete');
			if (s.find.length == s.find.concat(res.data.datas).length) {
				s.arr = false
			}
		})
	}
	f.domestic().then(function (res) {
		s.findomestic = res.data.datas
//		console.log(s.findomestic)
	})
	s.dom = true
	s.domesticMore = function () {
		f.domesticMore().then(function (res) {
			s.findomestic = s.findomestic.concat(res.data.datas)
			s.$broadcast('scroll.infiniteScrollComplete');
			if (s.find.length == s.find.concat(res.data.datas).length) {
				s.dom = false
			}
		})
	}
	s.ticket = true;
	s.around = false;
	s.domestic = false;
	s.broad = false;
	s.tabticket = function () {
	    s.ticket = true
		s.around = false;
		s.domestic = false;
		s.broad = false;
	}
	s.tabaround = function () {
		s.around = true
		s.ticket = false;
		s.domestic = false;
		s.broad = false;
	}
	s.tabdomestic = function () {
		s.domestic = true;
		 s.ticket = false;
		 s.around = false;
		 s.broad = false;
	}
	s.tabroad = function () {
		s.broad = true
		s.around = false;
		s.ticket = false;
		s.domestic = false;
	}
	
	//做动画
	s.doanimate = function(){
//		i.$getByHandle('mainScroll').getScrollView()
		$('.ticket img').each(function(){
			$(this).stop(true,true)
			$(this).animate({
				"transform-origin": 0 + '%' + '     ' + 100 + '%',
				"width":100+'%',
				"height":100 + '%',
			})
		})
	}
	s.doRefresh = function() {
	    t(function(){
			console.log("刷新完成了");
			s.$broadcast('scroll.refreshComplete');
		},2000);
  };
}])

.controller('hotel',['$scope','hotel',function (s,h) {
	//二级返回页面
	s.back = function () {
		window.history.back()
	}
//	请求酒店大banner
	h.hotelBanner().then(function (res) {
		s.bigbanner = res.data.datas[0].infos
//		console.log(s.bigbanner)
	})
//酒店小banner
	h.sBanner().then(function (res) {
		s.sbanner = res.data.datas[2].infos
		s.target = res.data.datas[1].infos
		s.theme = res.data.datas[0].infos
		s.hot = res.data.datas[3].infos
//		console.log(s.sbanner)
	})
//销量排行
	h.billBoard().then(function (res) {
		s.sales = res.data.datas
		console.log(s.sales)
	})
	
}])
.controller('self-driving',['$scope','selftravel',function ($s,self) {
	//二级返回页面
	$s.back = function () {
		window.history.back()
	}
//	请求自驾游轮播图
self.selftra().then(function (res) {
		$s.selftraimg = res.data.datas[0].infos
	})
//  请求房车自驾
self.joinclub().then(function (res) {
		$s.joinc = res.data.datas[0].infos
	})
//  请求三亚自驾游
self.sanya().then(function (res) {
		$s.sany = res.data.datas[0].infos
	})
//  请求吃货
self.chihuo().then(function (res) {
		$s.chih = res.data.datas[0].infos
	})
//  请求往期
self.zijia().then(function (res) {
		$s.zij = res.data.datas[0].infos
	})
//  请求周末
self.week().then(function (res) {
		$s.weeks = res.data.datas[0].infos
		console.log(res.data.datas[0].infos)
	})
//  请求三小时
self.threehour().then(function (res) {
		$s.threeh = res.data.datas[0].infos
//		console.log(res.data.datas[0].infos)
	})
//  请求更远车程
self.longrange().then(function (res) {
		$s.lrange = res.data.datas[0].infos
		console.log(res.data.datas[0].infos)
	})
$s.bool1 = true
$s.moreweek = function () {
		self.moreweek()
		.then(function (res) {
			$s.weeks = $s.weeks.concat(res.data.datas[0].infos)
			if($s.weeks.length == $s.weeks.concat(res.data.datas[0].infos).length){
				$s.bool1 = false
			}
			console.log($s.weeks)
			$s.$broadcast('scroll.infiniteScrollComplete');
		})
	}
$s.bool2 = true
$s.morethreehour = function () {
		self.morethreehour()
		.then(function (res) {
			$s.threeh = $s.threeh.concat(res.data.datas[0].infos)
			if($s.threeh.length == $s.threeh.concat(res.data.datas[0].infos).length){
				$s.bool2 = false
			}
			console.log($s.threeh)
			$s.$broadcast('scroll.infiniteScrollComplete');
		})
	}
$s.bool3 = true
$s.morelongrange = function () {
		self.morelongrange()
		.then(function (res) {
			$s.lrange = $s.lrange.concat(res.data.datas[0].infos)
			if($s.lrange.length == $s.lrange.concat(res.data.datas[0].infos).length){
				$s.bool3 = false
			}
			console.log($s.lrange)
			$s.$broadcast('scroll.infiniteScrollComplete');
		})
	}
$s.boolweek = true;
$s.boolthree = false;
$s.boolrange = false;
$s.clickweek = function(){
	$s.boolweek = true;
	$s.boolthree = false;
	$s.boolrange = false;
}
$s.clickthree = function(){
	$s.boolweek = false;
	$s.boolthree = true;
	$s.boolrange = false;
}
$s.clickrange = function(){
	$s.boolweek = false;
	$s.boolthree = false;
	$s.boolrange = true;
}
}])


